const index_init = async () => {
    // 搜索框初始化事件
    searchInputFn();
    // 弹出公告窗口
    // showDialogTipsFn();
    // 关闭公告窗口
    $(".show-tips>.show-tips-main>.close").click(() => $(".show-tips").removeClass("active"));
};

// 搜索框初始化事件
const searchInputFn = () => {
    const inputDOM = document.querySelector(".search-input-val");
    if (!inputDOM) return;
    POWERMODE.colorful = true;
    POWERMODE.shake = false;
    //   输入框输入事件
    inputDOM.addEventListener("input", e => {
        POWERMODE(e);
        searchFn(e);
    });
    //   输入框聚焦事件
    inputDOM.addEventListener("focus", () => {
        $("body>main").animate({ scrollTop: 146 }, 366);
    });
};

// 输入框搜索事件
const searchFn = async e => {
    const inputVal = e.target.value.trim();
    if (inputVal == "") {
        return $(".article-list-item").css("display", "block");
    }
    $(".article-list-item").css("display", "none");
    $(".article-list-item").each(function (idx, i) {
        $(i).text().includes(inputVal) && $(i).css("display", "block");
    });
};

// 弹出框
const showDialogTipsFn = () => {
    // 展示KeyStr
    const date = new Date();
    const showStr = `${date.getMonth()}-${date.getDate()}`;
    const localShowStr = localStorage.getItem("localShowStr");
    if (String(showStr) == String(localShowStr)) return;
    localStorage.setItem("localShowStr", showStr);
    const tipDom = $(".show-tips");
    if (!tipDom) return;
    setTimeout(() => {
        tipDom.addClass("active");
    }, 666);
};

// 渲染Echarts
const renderEchartsFn = () => {
    const echartsJson = JSON.parse(echartArr);
    const myChart = echarts.init(document.querySelector(".statistics"), null, { renderer: "canvas", useDirtyRect: false });
    const dateList = echartsJson.map(i => i[0]);
    const valueList = echartsJson.map(i => i[1]);
    const option = {
        visualMap: [{ min: 0, max: 20000 }],
        grid: { left: "0", right: "0", bottom: "0", containLabel: true },
        tooltip: { trigger: "axis" },
        xAxis: { data: dateList },
        yAxis: { axisLabel: { show: false }, splitLine: { lineStyle: { color: "rgba(255, 255, 255, 0.06)" } } },
        series: [{ type: "line", lineStyle: { color: "#4A7F8A" }, showSymbol: false, data: valueList }]
    };
    if (option && typeof option === "object") {
        myChart.setOption(option);
    }
    window.addEventListener("resize", myChart.resize);
};

$(function () {
    index_init();
    renderEchartsFn();
});
